// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name:   TypeConvert.java

package com.haoxi.gateway.test.util ;


public class TypeConvert
{

    public TypeConvert ()
    {
    }

    public static int byte2int ( byte b[] , int offset )
    {
        return b[ offset + 3 ] & 0xff | ( b[ offset + 2 ] & 0xff ) << 8 |
                ( b[ offset + 1 ] & 0xff ) << 16 | ( b[ offset ] & 0xff ) << 24 ;
    }

    public static int byte2int ( byte b[] )
    {
        return b[ 3 ] & 0xff | ( b[ 2 ] & 0xff ) << 8 | ( b[ 1 ] & 0xff ) << 16 |
                ( b[ 0 ] & 0xff ) << 24 ;
    }

    public static byte[] toBinary
            ( int num,int len )
    {
        StringBuffer buffer = new StringBuffer () ;
        for ( int j = 31 ; j >= 0 ; j-- ) //bit operation which you can understand it easily
        {
            if ( ( ( 1 << j ) & num ) != 0 )
            {
                buffer.append ( "1" ) ;
            }
            else
            {
                buffer.append ( "0" ) ;
            }
        }
        int  strlength=buffer.toString().length();
        String returnStr=buffer.toString().substring(strlength-len,strlength);
        byte[] b=new byte[len];
        for(int i=0;i<returnStr.length();i++)
        {
            b[i]=(byte)Integer.parseInt(returnStr.substring(i,i+1));
        }
        return b;
    }

    public static long byte2long ( byte b[] )
    {
        return ( long ) b[ 7 ] & ( long ) 255 |
                ( ( long ) b[ 6 ] & ( long ) 255 ) << 8 |
                ( ( long ) b[ 5 ] & ( long ) 255 ) << 16 |
                ( ( long ) b[ 4 ] & ( long ) 255 ) << 24 |
                ( ( long ) b[ 3 ] & ( long ) 255 ) << 32 |
                ( ( long ) b[ 2 ] & ( long ) 255 ) << 40 |
                ( ( long ) b[ 1 ] & ( long ) 255 ) << 48 |
                ( long ) b[ 0 ] << 56 ;
    }

    public static long byte2long ( byte b[] , int offset )
    {
        return ( long ) b[ offset + 7 ] & ( long ) 255 |
                ( ( long ) b[ offset + 6 ] & ( long ) 255 ) << 8 |
                ( ( long ) b[ offset + 5 ] & ( long ) 255 ) << 16 |
                ( ( long ) b[ offset + 4 ] & ( long ) 255 ) << 24 |
                ( ( long ) b[ offset + 3 ] & ( long ) 255 ) << 32 |
                ( ( long ) b[ offset + 2 ] & ( long ) 255 ) << 40 |
                ( ( long ) b[ offset + 1 ] & ( long ) 255 ) << 48 |
                ( long ) b[ offset ] << 56 ;
    }

    public static byte[] int2byte ( int n )
    {
        byte b[] = new byte[4 ] ;
        b[ 0 ] = ( byte ) ( n >> 24 ) ;
        b[ 1 ] = ( byte ) ( n >> 16 ) ;
        b[ 2 ] = ( byte ) ( n >> 8 ) ;
        b[ 3 ] = ( byte ) n ;
        return b ;
    }

    public static void int2byte ( int n , byte buf[] , int offset )
    {
        buf[ offset ] = ( byte ) ( n >> 24 ) ;
        buf[ offset + 1 ] = ( byte ) ( n >> 16 ) ;
        buf[ offset + 2 ] = ( byte ) ( n >> 8 ) ;
        buf[ offset + 3 ] = ( byte ) n ;
    }

    public static byte[] short2byte ( int n )
    {
        byte b[] = new byte[2 ] ;
        b[ 0 ] = ( byte ) ( n >> 8 ) ;
        b[ 1 ] = ( byte ) n ;
        return b ;
    }

    public static void short2byte ( int n , byte buf[] , int offset )
    {
        buf[ offset ] = ( byte ) ( n >> 8 ) ;
        buf[ offset + 1 ] = ( byte ) n ;
    }

    public static byte[] long2byte ( long n )
    {
        byte b[] = new byte[8 ] ;
        b[ 0 ] = ( byte ) ( int ) ( n >> 56 ) ;
        b[ 1 ] = ( byte ) ( int ) ( n >> 48 ) ;
        b[ 2 ] = ( byte ) ( int ) ( n >> 40 ) ;
        b[ 3 ] = ( byte ) ( int ) ( n >> 32 ) ;
        b[ 4 ] = ( byte ) ( int ) ( n >> 24 ) ;
        b[ 5 ] = ( byte ) ( int ) ( n >> 16 ) ;
        b[ 6 ] = ( byte ) ( int ) ( n >> 8 ) ;
        b[ 7 ] = ( byte ) ( int ) n ;
        return b ;
    }

    public static int Bytes4ToInt ( byte mybytes[] )
    {
        return ( 0xff & mybytes[ 0 ] ) << 24 | ( 0xff & mybytes[ 1 ] ) << 16 |
                ( 0xff & mybytes[ 2 ] ) << 8 | 0xff & mybytes[ 3 ] ;
    }

    public static void long2byte ( long n , byte buf[] , int offset )
    {
        buf[ offset ] = ( byte ) ( int ) ( n >> 56 ) ;
        buf[ offset + 1 ] = ( byte ) ( int ) ( n >> 48 ) ;
        buf[ offset + 2 ] = ( byte ) ( int ) ( n >> 40 ) ;
        buf[ offset + 3 ] = ( byte ) ( int ) ( n >> 32 ) ;
        buf[ offset + 4 ] = ( byte ) ( int ) ( n >> 24 ) ;
        buf[ offset + 5 ] = ( byte ) ( int ) ( n >> 16 ) ;
        buf[ offset + 6 ] = ( byte ) ( int ) ( n >> 8 ) ;
        buf[ offset + 7 ] = ( byte ) ( int ) n ;
    }
}
